home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8343 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How can I pick out charactors from argv[ ] ?
  5. Date: 3 Mar 1996 12:24:31 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4hc31v$fi5@sparcserver.lrz-muenchen.de>
  9. References: <4hbcsh$3do@netnews.ntu.edu.tw>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. antony@public.bta.net.cn (Antony Yandong Chen) writes:
  13.  
  14. >Hi
  15.  
  16. >I got this from a C turtorial book:
  17.  
  18. >main (argc,argv)
  19. >int argc;
  20. >char *argv[];
  21.  
  22. Your C turtorial book seems to be quite old. "Old style" function 
  23. definitions should _not_ be used, except if there is a good 
  24. technical reason (e.g. no ANSI C compiler for the target system).
  25.  
  26. "Implicit int" functions are bad style even in K&R C, imho. So
  27. try to see whether your compiler accepts
  28.  
  29. int main(int argc, char *argv[])
  30.  
  31. >{
  32. >        printf("argc = %d\n",argc);
  33.  
  34. You should _not_ access argv[1] if you did not check whether 
  35. argc is greater than 1. 
  36.  
  37. >        printf("argv1 = %s\n",argv[1]);
  38.  
  39. >}
  40.  
  41. >I could execute it OK, but I couldn't be able to pick out single 
  42. >charactors from string argv[], anybody can tell me how to make it?
  43.  
  44.   argv[1] is the second element in an array of pointers to char.
  45.   If argv[1] exists and points to at least 5 consecutive chars,
  46.   there are at least two semanically equivalent ways to access the
  47.   5th character:
  48.  
  49.      argv[1][4]    or    *(argv[1] + 4)
  50.  
  51. Kurt
  52. --
  53. | Kurt Watzka                             Phone : +49-89-2180-6254
  54. | watzka@stat.uni-muenchen.de
  55. | ua302aa@sunmail.lrz-muenchen.de
  56.  
  57.